import Vue from 'vue'
import Router from 'vue-router'
import routes from './routers'
import store from '@/store'
import iView from 'iview'
import {
  setTitle
} from '@/libs/util'

Vue.use(Router)
const router = new Router({
  routes,
  mode: 'history'
})
router.beforeEach((to, from, next) => {
  const { isLogin } = store.getters.userSetting
  if (!isLogin) {
    store.dispatch('loadUserSetting')
  }
  next()
})

router.afterEach(to => {
  setTitle(to, router.app)
  iView.LoadingBar.finish()
  window.scrollTo(0, 0)
})

export default router
